package com.mj.mybatis;

import com.mj.dao.IUserMapper;
import com.mj.domain.UserDO;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author 马洁
 * @date 2020/9/18 - 10:46
 */
public class MyBatisTest {
    public static void main(String[] args) throws IOException {
        start();
    }

    public static void start() throws IOException {
        InputStream inputStream = MyResources.getResourceAsStream("sqlMapConfig.xml");
        // 创建工厂
        MySqlSessionFactoryBuilder sqlSessionFactoryBuilder = new MySqlSessionFactoryBuilder();
        MySqlSessionFactory sqlSessionFactory;
        sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
        // 获取session连接
        MySqlSession sqlSession = sqlSessionFactory.openSession();
        // 获取针对接口创建的对象
        IUserMapper userMapper = sqlSession.getMapper(IUserMapper.class);
        // 进行查询
        List<UserDO> ls = userMapper.findAll();

        for (UserDO l : ls) {
            System.out.println(l);
        }

        sqlSession.close();
        inputStream.close();
    }
}
